var m_user = {};

m_user.param = {
		page: 1,
		rows: 10,
		name: null
}

m_user.pageBack = function(num, type) {
	m_user.param.page = num;
	m_user.getData();
}

m_user.pageInit = function(pageNum, page, pageChangeBack) {
	$('#pagination').empty();
    var jqPaginator = $.jqPaginator('#pagination', {
        totalPages: pageNum,
        visiblePages: 5,
        currentPage: page,
        first:'<li class="first" jp-role="first" jp-data="1"><a href="javascript:;">首页</a></li>',
        prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
        next: '<li class="next"><a href="javascript:;">下一页</a></li>',
        last:'<li class="last" jp-role="last" jp-data="100"><a href="javascript:;">尾页</a></li>',
        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
        //onPageChange: function (num, type) {
         //   $('#p1').text(type + '：' + num);
        //}
        onPageChange: pageChangeBack
    });
}

m_user.getData = function() {
	var url = "../userInfo/findUserInfoList.action";
	var req = new common.Request();
	var reqData = {};
	for (var key in m_user.param) {
		if (m_user.param[key] != null) {
			reqData[key] = m_user.param[key];
		}
	}
	$('.content .right .spread_list .data_tr').remove();
	req.sendMethodRequest("get", url, reqData, function(e){
		if (e != null && e.isSuccess) {
			var spread_list = $('#spread_list');
			for (var i = 0; i < e.info.length; i ++) {
				(function(i){
					var info = e.info[i];
					var emptyTr = $('<tr></tr>').addClass('data_tr').appendTo(spread_list);
					var emptyTd1 = $('<td></td>').appendTo(emptyTr);
					var emptyTd2 = $('<td></td>').appendTo(emptyTr);
					var emptyTd3 = $('<td></td>').appendTo(emptyTr);
					var emptyTd4 = $('<td></td>').appendTo(emptyTr);
					var emptyTd5 = $('<td></td>').appendTo(emptyTr);
					var dataTr = $('<tr></tr>').addClass('data_tr').appendTo(spread_list);
					var dataTd1 = $('<td></td>').html(info.name == null ? "" : info.name).appendTo(dataTr);
					var dataTd2 = $('<td></td>').html(info.companyName == null ? "" : info.companyName).appendTo(dataTr);
					var dataTd3 = $('<td></td>').html(info.realName == null ? "" : info.realName).appendTo(dataTr);
					var dataTd4 = $('<td></td>').html(info.moble == null ? "" : info.moble).appendTo(dataTr);
					var dataTd5 = $('<td></td>').appendTo(dataTr);
					var ziliao = $('<a></a>').html("资料 /").appendTo(dataTd5).click(function() {
						
					});
					var update = $('<a></a>').html(" 修改密码 /").appendTo(dataTd5).click(function() {
						
					});
					var renwen = $('<a></a>').html(" 查看任务 ").appendTo(dataTd5).click(function() {
						
					});
				})(i);
			}
			var init = false;
			m_user.pageInit(e.sum, m_user.param.page, function(num, type){
				m_user.param.page = num;
				if (init) {
					m_user.getData();
				} else {
					init = true;
				}
			});
		}
	}, function(e) {
		
	});
}

m_user.search = function() {
	$('#search_button').click(function(){
		var name_search = $('#name_search').val();
		if (name_search != null && common.string.Trim(name_search) != "") {
			m_user.param.name = name_search;
		} else {
			m_user.param.name = null;
		}
		m_user.getData();
	});
}

m_user.itemItem = function() {
	$('.item_con').click(function(){
		$('.item_con').removeClass('select');
		$(this).addClass('select');
	});
}

m_user.init = function() {
	m_user.itemItem();
	m_user.getData();
	m_user.search();
}

$(document).ready(function() {
	m_user.init();
});